
#ifndef __SOCKETMATTRANSMISSIONSEVER_H__
#define __SOCKETMATTRANSMISSIONSEVER_H__
 
#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "json/json.h"
 
using namespace cv;
using namespace std;
 
#define PACKAGE_NUM 2
 
#define IMG_WIDTH 640
#define IMG_HEIGHT 480
 
#define BLOCKSIZE IMG_WIDTH*IMG_HEIGHT*3/PACKAGE_NUM
 
struct recvBuf
{
	char* buf;
	int flag;
};
 
struct infohead
{
	int detectType;
	int width;
	int height;
	int packageNum;
};
 
class SocketMatTransmissionServer
{
public:
	SocketMatTransmissionServer(void);
	~SocketMatTransmissionServer(void);
	int sockConn;
	int server_sockfd;
	struct sockaddr_in server_sockaddr;

	int detectType;
	int width;
	int height;
	int packageNum;
	struct recvBuf data;
private:
		
 
	int needRecv;
	int count;
	char *clientIp;
	int port;	
	char strDirectory[80];
 
public:
 
	// 打开socket连接
	// params :	PORT	传输端口
	// return : -1		连接失败
	//			1		连接成功
	int socketConnect(int PORT, int flag);
 
 
	// 传输图像
	// params : image	待接收图像
	//		image	待接收图像
	// return : -1		接收失败
	//			1		接收成功
	int receive(cv::Mat& image);


	int receive(struct infohead& head);

	// 返回推理结果
	// params : res	推理结果
	// return : -1		返回失败
	//			1		返回成功
	int send_res(int res);
 
 
	// 断开socket连接
	void socketDisconnect(void);

	int socketAccept();
	int socketBind(int PORT);

	int createMultiLevelDir(char* sPathName);
	void writeOpencvMat(cv::Mat& image);
};
 
#endif